package com.qd.panda.stroke;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cdqidi.util.page.PageUtil;
import com.qd.common.panda.domain.entity.order.OrderDTO;
import com.qd.common.panda.domain.entity.order.OrderQueryDTO;
import com.qd.common.panda.domain.entity.order.TotalPreferentialAmountDTO;
import com.qd.common.panda.domain.entity.stroke.UserStrokeOrderDTO;
import com.qd.panda.service.stroke.order.UserStrokeOrderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;

/**
 * APP_用户订单
 *
 * @author sjk
 */
@RequiredArgsConstructor
@Validated
@RestController
@RequestMapping("/app/userOrder/")
@Slf4j
public class AppUserOrderController {
    private final UserStrokeOrderService userStrokeOrderService;


    /**
     * 用户订单详情
     *
     * @param orderId 订单ID
     * @return 订单详情
     */
    @GetMapping(value = "getUserOrderById")
    public UserStrokeOrderDTO getUserOrderById(@Validated @NotBlank(message = "订单ID不能为空") String orderId) {
        return userStrokeOrderService.getByIdDto(orderId);
    }

    /**
     * 用户订单列表
     *
     * @param dto 查询参数以及页数和每页显示条数
     * @return 列表信息
     */
    @GetMapping(value = "/userOrderPage")
    public IPage<OrderDTO> userOrderPage(OrderQueryDTO dto) {
        return userStrokeOrderService.userOrderPage(PageUtil.buildPage(dto), dto);
    }

    /**
     * 优惠总金额
     *
     * @param dto 查询参数以及页数和每页显示条数
     * @return 列表信息
     */
    @GetMapping(value = "/totalPreferentialAmount")
    public TotalPreferentialAmountDTO totalPreferentialAmount(OrderQueryDTO dto) {
        return userStrokeOrderService.totalPreferentialAmount(dto);
    }
}